package com.rmt.www.serviceImpl;

import oracle.net.aso.i;

import com.opensymphony.xwork2.ActionContext;
import com.rmt.www.service.DevManageImplService;
import com.rmt.www.utility.SystemTime;
import com.rmt.www.vo.*;
import com.rmt.www.constant.RequestType;
import com.rmt.www.dao.*;

public class DevManageImplServiceImpl implements DevManageImplService {
	
	private ImplementationArtifactRequestDao implementationArtifactRequestDao;
	private ImplementationArtifactDao implementationArtifactDao;
	private UserDao userDao;
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}


	public void addImplementationRequest(ImplementationArtifactRequest request) {
		implementationArtifactRequestDao.insertImplArtifactRequest(request);
	}

	public void deleteImplementation(int id) {
		ImplementationArtifact ia = implementationArtifactDao.getImplementationArtifactById(id);
		ImplementationArtifactRequest r = new ImplementationArtifactRequest();
		
		r.setPid(ia.getPid());
		r.setImplartifactid(ia.getId());
		r.setTitle(ia.getTitle());
		r.setFunction(ia.getFunction());
		r.setInput(ia.getInput());
		r.setOutput(ia.getOutput());
		r.setProcessingsteps(ia.getProcessingsteps());
		r.setAlgorithm(ia.getAlgorithm());
		r.setErrorhandling(ia.getErrorhandling());
		r.setLanguage(ia.getLanguage());
		r.setCode(ia.getCode());
		r.setPriority(ia.getPriority());
		r.setEffort(ia.getEffort());
		r.setCost(ia.getCost());
		r.setRisk(ia.getRisk());
		r.setComment(ia.getComment());
		r.setUpdatedtimes(ia.getUpdatedtimes());
		r.setVersion(ia.getVersion());
		r.setStatus(ia.getStatus());
		r.setCreaterid(ia.getCreaterid());
		r.setCreatedtime(ia.getCreatedtime());
		
		r.setUpdatedtime(new java.sql.Timestamp(SystemTime.getSystemTime().getTime()));
		User u=(User)ActionContext.getContext().getSession().get("currentUser");
		r.setUpdaterid(u.getUid());
		r.setRequesttype(RequestType.DELETE);
		implementationArtifactRequestDao.insertImplArtifactRequest(r);
	}

	public void updateImplementation(ImplementationArtifactRequest request) {
		// TODO Auto-generated method stub

	}

	public ImplementationArtifactRequestDao getImplementationArtifactRequestDao() {
		return implementationArtifactRequestDao;
	}

	public void setImplementationArtifactRequestDao(
			ImplementationArtifactRequestDao implementationArtifactRequestDao) {
		this.implementationArtifactRequestDao = implementationArtifactRequestDao;
	}

	public ImplementationArtifactDao getImplementationArtifactDao() {
		return implementationArtifactDao;
	}

	public void setImplementationArtifactDao(
			ImplementationArtifactDao implementationArtifactDao) {
		this.implementationArtifactDao = implementationArtifactDao;
	}

	public ImplementationArtifact getImplementationArtifact(int id) {
		ImplementationArtifact a = implementationArtifactDao.getImplementationArtifactById(id);
		a.set_authorname(userDao.getUser(a.getCreaterid()).getName());
 		a.set_updatername(userDao.getUser(a.getUpdaterid()).getName());
 		return a;
	}

}
